Menu
Bantuan:Templat Contoh penggunaan templatJika anda ingin mencuba templat-templat di bawah, sila gunakan templat kotak pasir
Untuk melihat contoh templat yang paling mudah, perhatikan Template:Tc. Templat ini membantu mengalihkan huruf di "dalam" ke halaman lain. Contohnya, menyunting frasa berikut ke mana-mana halaman akan menghasilkan hasil seperti di bawah:
Penerangan | Perkataan yang dimasukkan | Hasilnya |
---|---|---|
Hanya {{Tc}} | {{tc}} | {{tlc|...}} |
Hanya satu penggunaan {{tc}} dalam teks | {{tc}} 2009, with Barack Obama settling into the White House, we find the beginning of... | {{tlc|...}} 2009, with Barack Obama settling into the White House, we find the beginning of... |
Penggunaan {{tc}} yang banyak dalam teks | {{tc}} 2009, with Barack Obama settl{{tc}}g {{tc}}to the White House, we f{{tc}}d the beg{{tc}}n{{tc}}g of... | {{tlc|...}} 2009, with Barack Obama settl{{tlc|...}} g {{tlc|...}} to the White House, we f{{tlc|...}} d the beg{{tlc|...}} n{{tlc|...}} g of... |
Anda akan perasan bahawa templat tersebut hanya mengandungi huruf "dalam" apabila dikosongkan, walaupun ada teks penjelasan pada halaman templat ("Templat ini digunakan ..." klik pada pautan templat di atas untuk melihat). Jika anda menyunting halaman templat, (klik pautan ini), anda akan melihat semuanya kecuali huruf-huruf di"dalam" yang disertakan dalam 'noinclude', yang akan dibincangkan kemudian.
Transclusion with parameters is only slightly more complicated. For a quick example, the famous dead man's hand can be reproduced by the following templates, using unnamed parameters:
Description | Text Entered | Result after Processing |
---|---|---|
using three templates (Template:Clubs, Template:Diamonds, and Template:Spades) | {{ clubs |A}} {{ clubs |8}} {{ spades |A}} {{ spades |8}} {{ diamonds |9}} | A♣ 8♣ A♠ 8♠ 9♦ |
Using (Template:BridgeHandInline); not quite as pretty, but just one template, with four parameters. | {{ BridgeHandInline |A8||9|A8}} | ♠ A8 ♥ ♦ 9 ♣ A8 |
Using (Template:BridgeHandInline), but with a missing pipe separator | {{ BridgeHandInline |A8|9|A8}} | ♠ A8 ♥ 9 ♦ A8 ♣ {{{4}}} |
In the second example, the position of the parameter in the template tag determines which suit it belongs to. Thus, the first A8 (first slot) goes to spades, the empty position (second slot) goes to hearts, the 9 (third slot) goes to diamonds, the second A8 (fourth slot) goes to clubs. Note that the empty parameter position is counted; if the extra pipe is forgotten, as in the third example, the result is that the cards end up in the wrong positions, and a {{{4}}} appears, meaning that the template was expecting a value for the fourth positional parameter but none was provided. See the section on parameters and default values, below.
Using named parameters is similar to using unnamed parameters. For example, Template:Payoff matrix (which is used in some game theory pages) gives a simple 2-by-2 grid with adjustable values, using the names UL, UR, DL, and DR to refer to Up Left, Up Right, Down Left and Down Right, and a Name parameter to add a name to the bottom of the matrix.
Description | Code | Result |
---|---|---|
Payoff matrix | {{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }} | Templat:Payoff matrix |
Payoff matrix showing a default value for a missing parameter, and different ordering for the others | {{payoff matrix | DR = 9 | Name = Example usage | DL = 2 | UR = 7 }} | Templat:Payoff matrix |
In the second case, the order of the parameters has been altered without changing the result - one of the advantages that named parameters have over unnamed parameters - and one of the values (UL) has been removed entirely, allowing the template to insert the default value of "0, 0".
Parameter names are case sensitive, even in the first character. for example, using "dr = 9","Dr = 9" or "dR = 9" instead of "DR = 9" will cause the Down Right cell to display the default "0, 0". The alternate case versions are treated as different parameters and ignored by the template.
Generally, templates are processed into readable text when a user browses a page. This is the normal intention of a template: since the template is reevaluated each time it's used, changes to the template can propagate across many pages quickly and effortlessly. Occasionally, however, this is not appropriate. For instance, a user may want a template which returns a date or time that remains fixed, rather than changing each time the page is browsed. For those cases there is substitution, which is done by adding subst: before the template name in the template tag. substitution does exactly what its name suggests: rather than processing the template each time the page is browsed, substitution processes the template at the time the edit is saved, and replaces the template tag with the processed results.
For example, the template {{tc}} (as shown above) adds the letters "in" wherever it is placed. Thus, the wikitext bra{{tc}} will produce the word bra{{tlc|...}}
. The wikitext will always remain as bra{{tc}}, however, so if {{tc}} is changed so that it adds the letters "wn", the wikitext will produce brawn instead of brain. Substituting like so - bra{{subst:tc}} - will permanently change the wikitext to read brain, and later changes to the template {{tc}} will have no effect on the substituted text.
In general, substitution processes one level, so if the template in question contains other template tags, those template tags will be substituted in, rather than the processed results of those tags. This is a sometimes useful trick when debugging complex templates. For information on multi-level substitution, see Help:Substitution#Multilevel substitution. Articles where templates were substituted rather than transcluded are listed on WikiProject Check Wikipedia#Template programming element.
Menu
Bantuan:Templat Contoh penggunaan templatBerkaitan
Bantuan pengangguran Bantuan Bantuan kemanusiaan Bantuan brek kecemasan Bantuan Rakyat 1Malaysia Bantuan Motor Bersepadu Bantuan pembangunan rasmi Bantul Bantul, Bantul Bantuil, Cerbon, Barito KualaRujukan
WikiPedia: Bantuan:Templat http://translate.google.com/translate?u=https://en... http://prpm.dbp.gov.my/ http://meta.wikimedia.org//w/index.php?title=Bantu... http://meta.wikimedia.org//w/index.php?title=Bantu... http://en.wikipedia.org/w/index.php?title=Template... https://meta.wikimedia.org/wiki/Help:Template?oldi... https://meta.wikimedia.org/wiki/Template:Loop1?act...